<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>expr.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_datasource_expr.js.html">expr.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2006 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview
<a name="line17"></a> * Expression evaluation utilities. Expression format is very similar to XPath.
<a name="line18"></a> *
<a name="line19"></a> * Expression details:
<a name="line20"></a> * - Of format A/B/C, which will evaluate getChildNode(&#39;A&#39;).getChildNode(&#39;B&#39;).
<a name="line21"></a> *    getChildNodes(&#39;C&#39;)|getChildNodeValue(&#39;C&#39;)|getChildNode(&#39;C&#39;) depending on
<a name="line22"></a> *    call
<a name="line23"></a> * - If expression ends with &#39;/name()&#39;, will get the name() of the node
<a name="line24"></a> *    referenced by the preceding path.
<a name="line25"></a> * - If expression ends with &#39;/count()&#39;, will get the count() of the nodes that
<a name="line26"></a> *    match the expression referenced by the preceding path.
<a name="line27"></a> * - If expression ends with &#39;?&#39;, the value is OK to evaluate to null. This is
<a name="line28"></a> *    not enforced by the expression evaluation functions, instead it is
<a name="line29"></a> *    provided as a flag for client code which may ignore depending on usage
<a name="line30"></a> * - If expression has [INDEX], will use getChildNodes().getByIndex(INDEX)
<a name="line31"></a> *
<a name="line32"></a> */
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>goog.provide(&#39;goog.ds.Expr&#39;);
<a name="line36"></a>
<a name="line37"></a>goog.require(&#39;goog.ds.BasicNodeList&#39;);
<a name="line38"></a>goog.require(&#39;goog.ds.EmptyNodeList&#39;);
<a name="line39"></a>goog.require(&#39;goog.string&#39;);
<a name="line40"></a>
<a name="line41"></a>
<a name="line42"></a>/**
<a name="line43"></a> * Create a new expression. An expression uses a string expression language, and
<a name="line44"></a> * from this string and a passed in DataNode can evaluate to a value, DataNode,
<a name="line45"></a> * or a DataNodeList.
<a name="line46"></a> *
<a name="line47"></a> * @param {string} opt_expr The string expression.
<a name="line48"></a> * @constructor
<a name="line49"></a> */
<a name="line50"></a>goog.ds.Expr = function(opt_expr) {
<a name="line51"></a>  if (opt_expr) {
<a name="line52"></a>    this.setSource_(opt_expr);
<a name="line53"></a>  }
<a name="line54"></a>};
<a name="line55"></a>
<a name="line56"></a>
<a name="line57"></a>/**
<a name="line58"></a> * Set the source expression text &amp; parse
<a name="line59"></a> *
<a name="line60"></a> * @param {string} expr The string expression source.
<a name="line61"></a> * @param {Array} opt_parts Array of the parts of an expression.
<a name="line62"></a> * @param {goog.ds.Expr} opt_childExpr Optional child of this expression,
<a name="line63"></a> *   passed in as a hint for processing.
<a name="line64"></a> * @param {goog.ds.Expr} opt_prevExpr Optional preceding expression
<a name="line65"></a> *   (i.e. $A/B/C is previous expression to B/C) passed in as a hint for
<a name="line66"></a> *   processing.
<a name="line67"></a> * @private
<a name="line68"></a> */
<a name="line69"></a>goog.ds.Expr.prototype.setSource_ = function(expr, opt_parts,
<a name="line70"></a>    opt_childExpr, opt_prevExpr) {
<a name="line71"></a>  this.src_ = expr;
<a name="line72"></a>
<a name="line73"></a>  if (!opt_childExpr &amp;&amp; !opt_prevExpr) {
<a name="line74"></a>    // Check whether it can be empty
<a name="line75"></a>    if (goog.string.endsWith(expr, goog.ds.Expr.String_.CAN_BE_EMPTY)) {
<a name="line76"></a>      this.canBeEmpty_ = true;
<a name="line77"></a>      expr = expr.substring(0, expr.length - 1);
<a name="line78"></a>    }
<a name="line79"></a>
<a name="line80"></a>    // Check whether this is an node function
<a name="line81"></a>    if (goog.string.endsWith(expr, &#39;()&#39;)) {
<a name="line82"></a>      if (goog.string.endsWith(expr, goog.ds.Expr.String_.NAME_EXPR) ||
<a name="line83"></a>          goog.string.endsWith(expr, goog.ds.Expr.String_.COUNT_EXPR) ||
<a name="line84"></a>          goog.string.endsWith(expr, goog.ds.Expr.String_.POSITION_EXPR)){
<a name="line85"></a>        var lastPos = expr.lastIndexOf(goog.ds.Expr.String_.SEPARATOR);
<a name="line86"></a>        if (lastPos != -1) {
<a name="line87"></a>          this.exprFn_ = expr.substring(lastPos + 1);
<a name="line88"></a>          expr = expr.substring(0, lastPos);
<a name="line89"></a>        } else {
<a name="line90"></a>          this.exprFn_ = expr;
<a name="line91"></a>          expr = goog.ds.Expr.String_.CURRENT_NODE_EXPR;
<a name="line92"></a>        }
<a name="line93"></a>        if (this.exprFn_ == goog.ds.Expr.String_.COUNT_EXPR) {
<a name="line94"></a>          this.isCount_ = true;
<a name="line95"></a>        }
<a name="line96"></a>      }
<a name="line97"></a>    }
<a name="line98"></a>  }
<a name="line99"></a>
<a name="line100"></a>  // Split into component parts
<a name="line101"></a>  this.parts_ = opt_parts || expr.split(&#39;/&#39;);
<a name="line102"></a>  this.size_ = this.parts_.length;
<a name="line103"></a>  this.last_ = this.parts_[this.size_ - 1];
<a name="line104"></a>  this.root_ = this.parts_[0];
<a name="line105"></a>
<a name="line106"></a>  if (this.size_ == 1) {
<a name="line107"></a>    this.rootExpr_ = this;
<a name="line108"></a>    this.isAbsolute_ = goog.string.startsWith(expr, &#39;$&#39;);
<a name="line109"></a>  } else {
<a name="line110"></a>    this.rootExpr_ = goog.ds.Expr.createInternal_(this.root_, null,
<a name="line111"></a>        this, null);
<a name="line112"></a>    this.isAbsolute_ = this.rootExpr_.isAbsolute_;
<a name="line113"></a>    this.root_ = this.rootExpr_.root_;
<a name="line114"></a>  }
<a name="line115"></a>
<a name="line116"></a>  if (this.size_ == 1 &amp;&amp; !this.isAbsolute_) {
<a name="line117"></a>    // Check whether expression maps to current node, for convenience
<a name="line118"></a>    this.isCurrent_ = (expr == goog.ds.Expr.String_.CURRENT_NODE_EXPR ||
<a name="line119"></a>        expr == goog.ds.Expr.String_.EMPTY_EXPR);
<a name="line120"></a>
<a name="line121"></a>    // Whether this expression is just an attribute (i.e. &#39;@foo&#39;)
<a name="line122"></a>    this.isJustAttribute_ =
<a name="line123"></a>        goog.string.startsWith(expr, goog.ds.Expr.String_.ATTRIBUTE_START);
<a name="line124"></a>
<a name="line125"></a>    // Check whether this is a common node expression
<a name="line126"></a>    this.isAllChildNodes_ = expr == goog.ds.Expr.String_.ALL_CHILD_NODES_EXPR;
<a name="line127"></a>    this.isAllAttributes_ = expr == goog.ds.Expr.String_.ALL_ATTRIBUTES_EXPR;
<a name="line128"></a>    this.isAllElements_ = expr == goog.ds.Expr.String_.ALL_ELEMENTS_EXPR;
<a name="line129"></a>  }
<a name="line130"></a>};
<a name="line131"></a>
<a name="line132"></a>
<a name="line133"></a>/**
<a name="line134"></a> * Get the source data path for the expression
<a name="line135"></a> * @return {string} The path.
<a name="line136"></a> */
<a name="line137"></a>goog.ds.Expr.prototype.getSource = function() {
<a name="line138"></a>  return this.src_;
<a name="line139"></a>};
<a name="line140"></a>
<a name="line141"></a>
<a name="line142"></a>/**
<a name="line143"></a> * Gets the last part of the expression.
<a name="line144"></a> * @return {string?} Last part of the expression.
<a name="line145"></a> */
<a name="line146"></a>goog.ds.Expr.prototype.getLast = function() {
<a name="line147"></a>  return this.last_;
<a name="line148"></a>};
<a name="line149"></a>
<a name="line150"></a>
<a name="line151"></a>/**
<a name="line152"></a> * Gets the parent expression of this expression, or null if this is top level
<a name="line153"></a> * @return {goog.ds.Expr} The parent.
<a name="line154"></a> */
<a name="line155"></a>goog.ds.Expr.prototype.getParent = function() {
<a name="line156"></a>  if (!this.parentExprSet_) {
<a name="line157"></a>    if (this.size_ &gt; 1) {
<a name="line158"></a>      this.parentExpr_ = goog.ds.Expr.createInternal_(null,
<a name="line159"></a>          this.parts_.slice(0, this.parts_.length - 1), this, null);
<a name="line160"></a>    }
<a name="line161"></a>    this.parentExprSet_ = true;
<a name="line162"></a>  }
<a name="line163"></a>  return this.parentExpr_;
<a name="line164"></a>};
<a name="line165"></a>
<a name="line166"></a>
<a name="line167"></a>/**
<a name="line168"></a> * Gets the parent expression of this expression, or null if this is top level
<a name="line169"></a> * @return {goog.ds.Expr} The parent.
<a name="line170"></a> */
<a name="line171"></a>goog.ds.Expr.prototype.getNext = function() {
<a name="line172"></a>  if (!this.nextExprSet_) {
<a name="line173"></a>    if (this.size_ &gt; 1) {
<a name="line174"></a>      this.nextExpr_ = goog.ds.Expr.createInternal_(null, this.parts_.slice(1),
<a name="line175"></a>          null, this);
<a name="line176"></a>    }
<a name="line177"></a>    this.nextExprSet_ = true;
<a name="line178"></a>  }
<a name="line179"></a>  return this.nextExpr_;
<a name="line180"></a>};
<a name="line181"></a>
<a name="line182"></a>
<a name="line183"></a>/**
<a name="line184"></a> * Evaluate an expression on a data node, and return a value
<a name="line185"></a> * Recursively walks through child nodes to evaluate
<a name="line186"></a> * TODO Support other expression functions
<a name="line187"></a> *
<a name="line188"></a> * @param {goog.ds.DataNode} opt_ds Optional datasource to evaluate against.
<a name="line189"></a> *     If not provided, evaluates against DataManager global root.
<a name="line190"></a> * @return {Object?} Value of the node, or null if doesn&#39;t exist.
<a name="line191"></a> */
<a name="line192"></a>goog.ds.Expr.prototype.getValue = function(opt_ds) {
<a name="line193"></a>  if (opt_ds == null) {
<a name="line194"></a>    opt_ds = goog.ds.DataManager.getInstance();
<a name="line195"></a>  } else if (this.isAbsolute_) {
<a name="line196"></a>
<a name="line197"></a>    // TODO: Remove once JSCompiler&#39;s undefined properties warnings
<a name="line198"></a>    // don&#39;t error for guarded properties.
<a name="line199"></a>    var magicProps = {getDataRoot: 0};
<a name="line200"></a>
<a name="line201"></a>    opt_ds = opt_ds.getDataRoot ? opt_ds.getDataRoot() :
<a name="line202"></a>        goog.ds.DataManager.getInstance();
<a name="line203"></a>  }
<a name="line204"></a>
<a name="line205"></a>  if (this.isCount_) {
<a name="line206"></a>    var nodes = this.getNodes(opt_ds);
<a name="line207"></a>    return nodes.getCount();
<a name="line208"></a>  }
<a name="line209"></a>
<a name="line210"></a>  if (this.size_ == 1) {
<a name="line211"></a>    return opt_ds.getChildNodeValue(this.root_);
<a name="line212"></a>  } else if (this.size_ == 0) {
<a name="line213"></a>    return opt_ds.get();
<a name="line214"></a>  }
<a name="line215"></a>
<a name="line216"></a>  var nextDs = opt_ds.getChildNode(this.root_);
<a name="line217"></a>
<a name="line218"></a>  if (nextDs == null) {
<a name="line219"></a>    return null;
<a name="line220"></a>  } else {
<a name="line221"></a>    return this.getNext().getValue(nextDs);
<a name="line222"></a>  }
<a name="line223"></a>};
<a name="line224"></a>
<a name="line225"></a>
<a name="line226"></a>/**
<a name="line227"></a> * Evaluate an expression on a data node, and return matching nodes
<a name="line228"></a> * Recursively walks through child nodes to evaluate
<a name="line229"></a> *
<a name="line230"></a> * @param {goog.ds.DataNode} opt_ds Optional datasource to evaluate against.
<a name="line231"></a> *     If not provided, evaluates against data root.
<a name="line232"></a> * @param {boolean} opt_canCreate If true, will try to create new nodes.
<a name="line233"></a> * @return {goog.ds.DataNodeList} Matching nodes.
<a name="line234"></a> */
<a name="line235"></a>goog.ds.Expr.prototype.getNodes = function(opt_ds, opt_canCreate) {
<a name="line236"></a>  return /** @type {goog.ds.DataNodeList} */(this.getNodes_(opt_ds,
<a name="line237"></a>      false, opt_canCreate));
<a name="line238"></a>};
<a name="line239"></a>
<a name="line240"></a>
<a name="line241"></a>/**
<a name="line242"></a> * Evaluate an expression on a data node, and return the first matching node
<a name="line243"></a> * Recursively walks through child nodes to evaluate
<a name="line244"></a> *
<a name="line245"></a> * @param {goog.ds.DataNode} opt_ds Optional datasource to evaluate against.
<a name="line246"></a> *     If not provided, evaluates against DataManager global root.
<a name="line247"></a> * @param {boolean} opt_canCreate If true, will try to create new nodes.
<a name="line248"></a> * @return {goog.ds.DataNode} Matching nodes, or null if doesn&#39;t exist.
<a name="line249"></a> */
<a name="line250"></a>goog.ds.Expr.prototype.getNode = function(opt_ds, opt_canCreate) {
<a name="line251"></a>  return /** @type {goog.ds.DataNode} */(this.getNodes_(opt_ds,
<a name="line252"></a>      true, opt_canCreate));
<a name="line253"></a>};
<a name="line254"></a>
<a name="line255"></a>
<a name="line256"></a>/**
<a name="line257"></a> * Evaluate an expression on a data node, and return the first matching node
<a name="line258"></a> * Recursively walks through child nodes to evaluate
<a name="line259"></a> *
<a name="line260"></a> * @param {goog.ds.DataNode} opt_ds Optional datasource to evaluate against.
<a name="line261"></a> *     If not provided, evaluates against DataManager global root.
<a name="line262"></a> * @param {boolean} opt_selectOne Whether to return single matching DataNode
<a name="line263"></a> *     or matching nodes in DataNodeList.
<a name="line264"></a> * @param {boolean} opt_canCreate If true, will try to create new nodes.
<a name="line265"></a> * @return {goog.ds.DataNode|goog.ds.DataNodeList} Matching node or nodes,
<a name="line266"></a> *     depending on value of opt_selectOne.
<a name="line267"></a> * @private
<a name="line268"></a> */
<a name="line269"></a>goog.ds.Expr.prototype.getNodes_ = function(opt_ds, opt_selectOne,
<a name="line270"></a>    opt_canCreate) {
<a name="line271"></a>  if (opt_ds == null) {
<a name="line272"></a>    opt_ds = goog.ds.DataManager.getInstance();
<a name="line273"></a>  } else if (this.isAbsolute_) {
<a name="line274"></a>    opt_ds = opt_ds.getDataRoot ? opt_ds.getDataRoot() :
<a name="line275"></a>        goog.ds.DataManager.getInstance();
<a name="line276"></a>  }
<a name="line277"></a>
<a name="line278"></a>  if (this.size_ == 0 &amp;&amp; opt_selectOne) {
<a name="line279"></a>      return opt_ds;
<a name="line280"></a>  } else if (this.size_ == 0 &amp;&amp; !opt_selectOne) {
<a name="line281"></a>    return new goog.ds.BasicNodeList([opt_ds]);
<a name="line282"></a>  } else if (this.size_ == 1) {
<a name="line283"></a>    if (opt_selectOne) {
<a name="line284"></a>      return opt_ds.getChildNode(this.root_, opt_canCreate);
<a name="line285"></a>    }
<a name="line286"></a>    else {
<a name="line287"></a>      var possibleListChild = opt_ds.getChildNode(this.root_);
<a name="line288"></a>      if (possibleListChild &amp;&amp; possibleListChild.isList()) {
<a name="line289"></a>        return possibleListChild.getChildNodes();
<a name="line290"></a>      } else {
<a name="line291"></a>        return opt_ds.getChildNodes(this.root_);
<a name="line292"></a>      }
<a name="line293"></a>    }
<a name="line294"></a>  } else {
<a name="line295"></a>    var nextDs = opt_ds.getChildNode(this.root_, opt_canCreate);
<a name="line296"></a>    if (nextDs == null &amp;&amp; opt_selectOne) {
<a name="line297"></a>      return null;
<a name="line298"></a>    } else if (nextDs == null &amp;&amp; !opt_selectOne) {
<a name="line299"></a>      return new goog.ds.EmptyNodeList();
<a name="line300"></a>    }
<a name="line301"></a>    return this.getNext().getNodes_(nextDs, opt_selectOne, opt_canCreate);
<a name="line302"></a>  }
<a name="line303"></a>};
<a name="line304"></a>
<a name="line305"></a>
<a name="line306"></a>/**
<a name="line307"></a> * Whether the expression can be null.
<a name="line308"></a> *
<a name="line309"></a> * @type {boolean}
<a name="line310"></a> * @private
<a name="line311"></a> */
<a name="line312"></a>goog.ds.Expr.prototype.canBeEmpty_ = false;
<a name="line313"></a>
<a name="line314"></a>
<a name="line315"></a>/**
<a name="line316"></a> * The parsed paths in the expression
<a name="line317"></a> *
<a name="line318"></a> * @type {Array.&lt;string&gt;}
<a name="line319"></a> * @private
<a name="line320"></a> */
<a name="line321"></a>goog.ds.Expr.prototype.parts_ = [];
<a name="line322"></a>
<a name="line323"></a>
<a name="line324"></a>/**
<a name="line325"></a> * Number of paths in the expression
<a name="line326"></a> *
<a name="line327"></a> * @type {number?}
<a name="line328"></a> * @private
<a name="line329"></a> */
<a name="line330"></a>goog.ds.Expr.prototype.size_ = null;
<a name="line331"></a>
<a name="line332"></a>
<a name="line333"></a>/**
<a name="line334"></a> * The root node path in the expression
<a name="line335"></a> *
<a name="line336"></a> * @type {string}
<a name="line337"></a> * @private
<a name="line338"></a> */
<a name="line339"></a>goog.ds.Expr.prototype.root_;
<a name="line340"></a>
<a name="line341"></a>
<a name="line342"></a>/**
<a name="line343"></a> * The last path in the expression
<a name="line344"></a> *
<a name="line345"></a> * @type {string?}
<a name="line346"></a> * @private
<a name="line347"></a> */
<a name="line348"></a>goog.ds.Expr.prototype.last_ = null;
<a name="line349"></a>
<a name="line350"></a>
<a name="line351"></a>/**
<a name="line352"></a> * Whether the expression evaluates to current node
<a name="line353"></a> *
<a name="line354"></a> * @type {boolean}
<a name="line355"></a> * @private
<a name="line356"></a> */
<a name="line357"></a>goog.ds.Expr.prototype.isCurrent_ = false;
<a name="line358"></a>
<a name="line359"></a>
<a name="line360"></a>/**
<a name="line361"></a> * Whether the expression is just an attribute
<a name="line362"></a> *
<a name="line363"></a> * @type {boolean}
<a name="line364"></a> * @private
<a name="line365"></a> */
<a name="line366"></a>goog.ds.Expr.prototype.isJustAttribute_ = false;
<a name="line367"></a>
<a name="line368"></a>
<a name="line369"></a>/**
<a name="line370"></a> * Does this expression select all DOM-style child nodes (element and text)
<a name="line371"></a> *
<a name="line372"></a> * @type {boolean}
<a name="line373"></a> * @private
<a name="line374"></a> */
<a name="line375"></a>goog.ds.Expr.prototype.isAllChildNodes_ = false;
<a name="line376"></a>
<a name="line377"></a>
<a name="line378"></a>/**
<a name="line379"></a> * Does this expression select all DOM-style attribute nodes (starts with &#39;@&#39;)
<a name="line380"></a> *
<a name="line381"></a> * @type {boolean}
<a name="line382"></a> * @private
<a name="line383"></a> */
<a name="line384"></a>goog.ds.Expr.prototype.isAllAttributes_ = false;
<a name="line385"></a>
<a name="line386"></a>
<a name="line387"></a>/**
<a name="line388"></a> * Does this expression select all DOM-style element child nodes
<a name="line389"></a> *
<a name="line390"></a> * @type {boolean}
<a name="line391"></a> * @private
<a name="line392"></a> */
<a name="line393"></a>goog.ds.Expr.prototype.isAllElements_ = false;
<a name="line394"></a>
<a name="line395"></a>
<a name="line396"></a>/**
<a name="line397"></a> * The function used by this expression
<a name="line398"></a> *
<a name="line399"></a> * @type {string?}
<a name="line400"></a> * @private
<a name="line401"></a> */
<a name="line402"></a>goog.ds.Expr.prototype.exprFn_ = null;
<a name="line403"></a>
<a name="line404"></a>
<a name="line405"></a>/**
<a name="line406"></a> * Cached value for the parent expression.
<a name="line407"></a> * @type {goog.ds.Expr?}
<a name="line408"></a> * @private
<a name="line409"></a> */
<a name="line410"></a>goog.ds.Expr.prototype.parentExpr_ = null;
<a name="line411"></a>
<a name="line412"></a>
<a name="line413"></a>/**
<a name="line414"></a> * Cached value for the next expression.
<a name="line415"></a> * @type {goog.ds.Expr?}
<a name="line416"></a> * @private
<a name="line417"></a> */
<a name="line418"></a>goog.ds.Expr.prototype.nextExpr_ = null;
<a name="line419"></a>
<a name="line420"></a>
<a name="line421"></a>/**
<a name="line422"></a> * Create an expression from a string, can use cached values
<a name="line423"></a> *
<a name="line424"></a> * @param {string} expr The expression string.
<a name="line425"></a> * @return {goog.ds.Expr} The expression object.
<a name="line426"></a> */
<a name="line427"></a>goog.ds.Expr.create = function(expr) {
<a name="line428"></a>  var result = goog.ds.Expr.cache_[expr];
<a name="line429"></a>
<a name="line430"></a>  if (result == null) {
<a name="line431"></a>    result = new goog.ds.Expr(expr);
<a name="line432"></a>    goog.ds.Expr.cache_[expr] = result;
<a name="line433"></a>  }
<a name="line434"></a>  return result;
<a name="line435"></a>};
<a name="line436"></a>
<a name="line437"></a>
<a name="line438"></a>/**
<a name="line439"></a> * Create an expression from a string, can use cached values
<a name="line440"></a> * Uses hints from related expressions to help in creation
<a name="line441"></a> *
<a name="line442"></a> * @param {?string} opt_expr The string expression source.
<a name="line443"></a> * @param {Array} opt_parts Array of the parts of an expression.
<a name="line444"></a> * @param {goog.ds.Expr} opt_childExpr Optional child of this expression,
<a name="line445"></a> *   passed in as a hint for processing.
<a name="line446"></a> * @param {goog.ds.Expr} opt_prevExpr Optional preceding expression
<a name="line447"></a> *   (i.e. $A/B/C is previous expression to B/C) passed in as a hint for
<a name="line448"></a> *   processing.
<a name="line449"></a> * @return {goog.ds.Expr} The expression object.
<a name="line450"></a> * @private
<a name="line451"></a> */
<a name="line452"></a>goog.ds.Expr.createInternal_ = function(opt_expr, opt_parts, opt_childExpr,
<a name="line453"></a>    opt_prevExpr) {
<a name="line454"></a>  var expr = opt_expr || opt_parts.join(&#39;/&#39;);
<a name="line455"></a>  var result = goog.ds.Expr.cache_[expr];
<a name="line456"></a>
<a name="line457"></a>  if (result == null) {
<a name="line458"></a>    result = new goog.ds.Expr();
<a name="line459"></a>    result.setSource_(expr, opt_parts, opt_childExpr, opt_prevExpr);
<a name="line460"></a>    goog.ds.Expr.cache_[expr] = result;
<a name="line461"></a>  }
<a name="line462"></a>  return result;
<a name="line463"></a>};
<a name="line464"></a>
<a name="line465"></a>
<a name="line466"></a>/**
<a name="line467"></a> * Cache of pre-parsed expressions
<a name="line468"></a> * @private
<a name="line469"></a> */
<a name="line470"></a>goog.ds.Expr.cache_ = {};
<a name="line471"></a>
<a name="line472"></a>
<a name="line473"></a>/**
<a name="line474"></a> * Commonly used strings in expressions.
<a name="line475"></a> * @enum {string}
<a name="line476"></a> * @private
<a name="line477"></a> */
<a name="line478"></a>goog.ds.Expr.String_ = {
<a name="line479"></a>  SEPARATOR: &#39;/&#39;,
<a name="line480"></a>  CURRENT_NODE_EXPR: &#39;.&#39;,
<a name="line481"></a>  EMPTY_EXPR: &#39;&#39;,
<a name="line482"></a>  ATTRIBUTE_START: &#39;@&#39;,
<a name="line483"></a>  ALL_CHILD_NODES_EXPR: &#39;*|text()&#39;,
<a name="line484"></a>  ALL_ATTRIBUTES_EXPR: &#39;@*&#39;,
<a name="line485"></a>  ALL_ELEMENTS_EXPR: &#39;*&#39;,
<a name="line486"></a>  NAME_EXPR: &#39;name()&#39;,
<a name="line487"></a>  COUNT_EXPR: &#39;count()&#39;,
<a name="line488"></a>  POSITION_EXPR: &#39;position()&#39;,
<a name="line489"></a>  INDEX_START: &#39;[&#39;,
<a name="line490"></a>  INDEX_END: &#39;]&#39;,
<a name="line491"></a>  CAN_BE_EMPTY: &#39;?&#39;
<a name="line492"></a>};
<a name="line493"></a>
<a name="line494"></a>
<a name="line495"></a>/**
<a name="line496"></a> * Standard expressions
<a name="line497"></a> */
<a name="line498"></a>
<a name="line499"></a>/**
<a name="line500"></a> * The current node
<a name="line501"></a> */
<a name="line502"></a>goog.ds.Expr.CURRENT = goog.ds.Expr.create(
<a name="line503"></a>    goog.ds.Expr.String_.CURRENT_NODE_EXPR);
<a name="line504"></a>
<a name="line505"></a>/**
<a name="line506"></a> * For DOM interop - all DOM child nodes (text + element).
<a name="line507"></a> * Text nodes have dataName #text
<a name="line508"></a> */
<a name="line509"></a>goog.ds.Expr.ALL_CHILD_NODES =
<a name="line510"></a>    goog.ds.Expr.create(goog.ds.Expr.String_.ALL_CHILD_NODES_EXPR);
<a name="line511"></a>
<a name="line512"></a>/**
<a name="line513"></a> * For DOM interop - all DOM element child nodes
<a name="line514"></a> */
<a name="line515"></a>goog.ds.Expr.ALL_ELEMENTS =
<a name="line516"></a>    goog.ds.Expr.create(goog.ds.Expr.String_.ALL_ELEMENTS_EXPR);
<a name="line517"></a>
<a name="line518"></a>/**
<a name="line519"></a> * For DOM interop - all DOM attribute nodes
<a name="line520"></a> * Attribute nodes have dataName starting with &quot;@&quot;
<a name="line521"></a> */
<a name="line522"></a>goog.ds.Expr.ALL_ATTRIBUTES =
<a name="line523"></a>    goog.ds.Expr.create(goog.ds.Expr.String_.ALL_ATTRIBUTES_EXPR);
<a name="line524"></a>
<a name="line525"></a>/**
<a name="line526"></a> * Get the dataName of a node
<a name="line527"></a> */
<a name="line528"></a>goog.ds.Expr.NAME = goog.ds.Expr.create(goog.ds.Expr.String_.NAME_EXPR);
<a name="line529"></a>
<a name="line530"></a>/**
<a name="line531"></a> * Get the count of nodes matching an expression
<a name="line532"></a> */
<a name="line533"></a>goog.ds.Expr.COUNT = goog.ds.Expr.create(goog.ds.Expr.String_.COUNT_EXPR);
<a name="line534"></a>
<a name="line535"></a>/**
<a name="line536"></a> * Get the position of the &quot;current&quot; node in the current node list
<a name="line537"></a> * This will only apply for datasources that support the concept of a current
<a name="line538"></a> * node (none exist yet). This is similar to XPath position() and concept of
<a name="line539"></a> * current node
<a name="line540"></a> */
<a name="line541"></a>goog.ds.Expr.POSITION = goog.ds.Expr.create(goog.ds.Expr.String_.POSITION_EXPR);
</pre>


</body>
</html>
